package com.ostrich.note.utils;


import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.PutObjectRequest;
import com.amazonaws.services.s3.model.PutObjectResult;

import java.io.File;

public class UploadUtils {

    public static String upload(String filePath){
        String s = System.currentTimeMillis() + ".png";
        new Thread(new Runnable() {
            @Override
            public void run() {
                String ACCESS_KEY =  "AKIATPTD6DXMOXDCBWNR";
                String SECRET_KEY = "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";
                String MY_BUCKET =  "picture-ios";
                String OBJECT_KEY = "defaultKey";

                AWSCredentials credentials = new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY);
                AmazonS3 s3 = new AmazonS3Client(credentials);
                s3.setRegion(Region.getRegion(Regions.SA_EAST_1));
//https://picture-ios.s3.sa-east-1.amazonaws.com/a.b.c/note/1.png
                File file = new File( filePath);
                PutObjectRequest putObjectRequest = new PutObjectRequest(MY_BUCKET, "a.b.c/note/"+s, file);
                PutObjectResult putObjectResult = s3.putObject(putObjectRequest);

            }
        }).start();


        return "https://picture-ios.s3.sa-east-1.amazonaws.com/a.b.c/note/"+s;
    }
}
